cmake_minimum_required(VERSION 3.27)
project(study-clang C)

set(CMAKE_C_STANDARD 99)

# ================================================================================
# bin 目录下存最后生成的可执行文件
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

# 递归查找指定目录下的所有源文件
function(recursive_glob VAR DIRECTORY)
    file(GLOB_RECURSE _files ${DIRECTORY}/*.cpp ${DIRECTORY}/*.c)
    set(${VAR} ${${VAR}} ${_files} PARENT_SCOPE)
endfunction()
set(SRC_LIST "")
recursive_glob(SRC_LIST ${PROJECT_SOURCE_DIR}/src)

# 指定头文件路径
include_directories(include)
# ================================================================================

#if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT CMAKE_OSX_ARCHITECTURES)
#    message("CMAKE_OSX_ARCHITECTURES is empty")
##    execute_process(COMMAND arch OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
##    set(CMAKE_OSX_ARCHITECTURES "${ARCH}")
#    set(CMAKE_OSX_ARCHITECTURES "x86_64") #arch得到的是i386有点问题，uname -m 好一点，但是安装了 Rosetta 2 会有问题
#endif()

#if(NOT CMAKE_TOOLCHAIN_FILE)
#    message("CMAKE_TOOLCHAIN_FILE is empty")
#    set(CMAKE_TOOLCHAIN_FILE "/Users/admin/.vcpkg-clion/vcpkg/scripts/buildsystems/vcpkg.cmake")
#endif()

include(${CMAKE_TOOLCHAIN_FILE})

find_package(CURL REQUIRED)
find_package(unofficial-sqlite3 CONFIG REQUIRED)
find_package(unofficial-pcre CONFIG REQUIRED)
#find_package(ICU REQUIRED)

add_executable(main3
    ${SRC_LIST}
)

target_link_libraries(main3 PRIVATE CURL::libcurl)
target_link_libraries(main3 PRIVATE unofficial::sqlite3::sqlite3)
target_link_libraries(main3 PRIVATE unofficial::pcre::pcre unofficial::pcre::pcre16 unofficial::pcre::pcre32 unofficial::pcre::pcrecpp)
#target_link_libraries(main3 PRIVATE icu-uc icu-io icu-i18n)
